import 'package:flutter/material.dart';

class StateFulCase extends StatefulWidget {
  const StateFulCase({Key? key, required this.title}) : super(key: key);
  final String title;
  @override
  _StateFulCaseState createState() => _StateFulCaseState();
}

class _StateFulCaseState extends State<StateFulCase> {
  int count = 0;

  @override // 组件初始化
  void initState() {
    debugPrint('initState');
    super.initState();
  }

  @override // 依赖项变化
  void didChangeDependencies() {
    debugPrint('didChangeDependencies');
    // TODO: implement didChangeDependencies
    super.didChangeDependencies();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        child: Column(
      children: [
        Text(
          widget.title,
          style: const TextStyle(fontSize: 40),
        ),
        Row(
          children: [
            ElevatedButton(
                onPressed: () {
                  setState(() {
                    count--;
                  });
                },
                child: const Text('-')),
            Text(count.toString(), style: const TextStyle(fontSize: 40)),
            ElevatedButton(
                onPressed: () {
                  setState(() {
                    count++;
                  });
                },
                child: const Text('+')),
          ],
        ),
      ],
    ));
  }
}
